<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ajax2以get方式传值处理</title>
  <script>
    function ajax4() {
        //1.创建ajax1对象
  let xmlHttpRequest = new XMLHttpRequest();

  xmlHttpRequest.open("get","/servletstudy_war_exploded/ajax3",true);

  xmlHttpRequest.onreadystatechange=function (){

    if (xmlHttpRequest.readyState == 4){
      if (xmlHttpRequest.status==200){
        let data = JSON.parse(xmlHttpRequest.responseText);
        //把json格式的字符串转换成json格式的对象 序列化
        console.log("data"+data[1].name);
          console.log("data"+data[1].age);
          document.querySelector(".name").innerHTML=data[1].name;
          document.querySelector(".age").innerHTML=data[1].age;
          document.querySelector(".major").innerHTML=data[1].major;
    }
    }
  }
  xmlHttpRequest.send();
    }
  </script>
</head>
<body onload="ajax4()">
<div id="show" style="border: solid 3px red;width: 500px;height: 100px; background: lightblue;">
姓名：<span class="name"></span>
    年龄：<span class="age"></span>
    专业：<span class="major"></span>
</div>
</body>
</html>